var StatusMessage = {
	TRANSIENT:0,  // Value comes and goes after timeout
	STICKY:1, // Keeps the value permanently, until explicit removed or modified
	RESET:2, // Removes the status bar
	timeOutValue : 3000
};

/* 
 * msg = string to show
 * (optional) type = one of the types mentioned above in StatusMessage, ie TRANSIENT, STICKY or RESET
 * (optional) timeoutValue = how long to show. 
 */
function showStatusMessage(msg, type, timeOutValue)
{
	var smc = $("#statusMessageContainer");
	var smt = $("#statusMessage");

	if (!type) type = StatusMessage.TRANSIENT; 
	if (!timeOutValue) timeOutValue = StatusMessage.timeOutValue;
	
	var removeStatus = function() {
		smc.animate({top: "-100"}, 1000, function() {smc.css("display", "none");});
	};
	
	var showStatus = function(msg) {
		smc.css("display", "block");
		smt.text(msg);
		smc.animate({top: "-5"}, 1000, $.noop);		
	};
	
	switch (type) {
		case StatusMessage.TRANSIENT:
			showStatus(msg);
			window.setTimeout(removeStatus, timeOutValue);
			break;
		case StatusMessage.STICKY:
			showStatus(msg);
			break;
		case StatusMessage.RESET:
			removeStatus();
			break;
	}
}

// Log to console
function logC(msg)
{
	console.log(msg);
}

// Log to debug log
// TODO: Currently it will log to console
function logD(msg)
{
	console.log(msg);
}

var PopupInfo = {
	backgroundId : "generic_popup_background"
};

function blanket_size(contentId, containerId) {
    if (typeof window.innerWidth != 'undefined') {
        viewportheight = window.innerHeight;
    } else {
        viewportheight = document.documentElement.clientHeight;
    }
    if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
        blanket_height = viewportheight;
    } else {
        if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
            blanket_height = document.body.parentNode.clientHeight;
        } else {
            blanket_height = document.body.parentNode.scrollHeight;
        }
    }
    var blanket = document.getElementById(containerId);
    blanket.style.height = blanket_height + 'px';
    /*
    var popUpDiv = document.getElementById(contentId);
    popUpDiv_height = blanket_height / 2 - 250; //150 is half popup's height
    popUpDiv.style.top = popUpDiv_height + 'px';
    */
}

function window_pos(contentId, containerId) {
    if (typeof window.innerWidth != 'undefined') {
        viewportwidth = window.innerHeight;
    } else {
        viewportwidth = document.documentElement.clientHeight;
    }
    if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
        window_width = viewportwidth;
    } else {
        if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
            window_width = document.body.parentNode.clientWidth;
        } else {
            window_width = document.body.parentNode.scrollWidth;
        }
    }
    /*
    var popUpDiv = document.getElementById(contentId);
    window_width = window_width / 2 - 250; //150 is half popup's width
    popUpDiv.style.left = window_width + 'px';
    */
}

function showPopup(contentId) {
    blanket_size(contentId, PopupInfo.backgroundId);
    window_pos(contentId, PopupInfo.backgroundId);
    $("#"+contentId).show();
    $("#"+PopupInfo.backgroundId).show();
}

function hidePopup(contentId) {
    $("#"+contentId).hide();
    $("#"+PopupInfo.backgroundId).hide();	
}

